package com.example.jbmsuppliers.sinopec.activity;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.Button;
import android.widget.TextView;

import com.example.jbmsuppliers.R;
import com.example.jbmsuppliers.sinopec.adapter.FragmentAdapter;
import com.example.jbmsuppliers.sinopec.fragment.ListFragmentGoods;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * 商家中心
 * Created by 家帮忙 on 2017/3/2.
 */

public class MyGoods extends ActivityUse {

    @InjectView(R.id.goback_ps_all)
    Button gobackPsAll;
    @InjectView(R.id.tabs)
    TabLayout tabs;
    @InjectView(R.id.viewpagerfb)
    ViewPager viewpagerfb;
    @InjectView(R.id.goodsfab)
    TextView goodsfab;

    //用来设置下表
    int currentIndex=0;

    @Override
    protected int setContentView1() {
        return R.layout.lz_issue;
    }

    @Override
    protected void initView() {
        ButterKnife.inject(this);
        setTitle();
        goodsfab.setText("我的商品");
    }
    public interface getDateType {
        void setType(int i);


    }

    public void setTitle() {//设置标题栏
        List<String> titles = new ArrayList<>();
        titles.add("已发布");
        titles.add("未通过");
        for (int i = 0; i < titles.size(); i++) {
            tabs.addTab(tabs.newTab().setText(titles.get(i)));
        }
        final List<Fragment> fragments = new ArrayList<>();
        for (int i = 0; i < titles.size(); i++) {
            fragments.add(new ListFragmentGoods());
        }
        FragmentAdapter mFragmentAdapteradapter = new FragmentAdapter(getSupportFragmentManager(), fragments, titles);
        //给ViewPager设置适配器
        viewpagerfb.setAdapter(mFragmentAdapteradapter);
        //将TabLayout和ViewPager关联起来。
        tabs.setupWithViewPager(viewpagerfb);
        //给TabLayout设置适配器
        tabs.setTabsFromPagerAdapter(mFragmentAdapteradapter);

        viewpagerfb.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch(position){
                    case 0:
                        currentIndex=0;
                        break;
                    case 1:
                        currentIndex=2;
                        break;
                }
                ((ListFragmentGoods)fragments.get(position)).setType(currentIndex);

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
       // ((ListFragmentGoods)fragments.get(0)).setType(0);
    }

    @OnClick(R.id.goback_ps_all)
    public void onClick() {
        finish();
    }


}
